<template>
    <view class="content">
        <view class="nav">
            <view :class="{active : type == 1}" @click="chooseNav(1)">待回访</view>
            <view :class="{active : type == 2}" @click="chooseNav(2)">已回访</view>
        </view>
        
        <view class="item" v-for="(item,index) in list" :key='index'>
            <view >经纪人：{{item.broker_name}}</view>
            <view class="u-p-t-10">联系电话：{{item.broker_phone}}</view>
            <view class="btns">
                <view @click="$gTo('/mine/pages/record/follow-details?id='+ item.id)">查看详情</view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [], 
                type: 1,
            }
        },
        onLoad() {
            this.getList()
            
            // 接收详情返回的监听
            uni.$on('BACK_FOLLOW', () => {
                this.page = 1;
                this.list = [];
                this.status = 'loadmore';
                this.getList();
            })
            
            // 接收推送 监听
            uni.$on('DHFXX', () => {
                this.page = 1;
                this.list = [];
                this.status = 'loadmore';
                this.getList();
            })
        },
        
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            chooseNav(num) {
                if (this.type == num) return
                this.type = num
                this.page = 1
                this.list = []
                this.status = 'loadmore'
                this.getList()
            },
            
            // 获取列表
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('user_follow_up', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    status: this.type == 1 ? 1 : 3,//1待回访 3已回访
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail && ret.detail.data && ret.detail.data.length > 0) {
            				this.list = this.list.concat(ret.detail.data);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        },
    }
</script>

<style lang="scss">
    page {
        background: #f5f5f5;
        border-top: 2rpx solid #e6e6e6;
    }
    .nav{
        background-color: #fff;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20rpx;
    }
    .nav>view{
        width: calc(100vw / 2);
        font-size: 26rpx;
        text-align: center;
        padding: 30rpx 0;
    }
    .active{
        font-size: 28rpx;
        font-weight: bold;
        color: #00a1e9;
        border-bottom: 2rpx solid #00a1e9;
    }
    .item{
        background-color: #fff;
        border-radius: 20rpx;
        padding: 30rpx 25rpx;
        margin: 0 20rpx 20rpx;
        font-size: 24rpx;
    }
    .btns{
        display: flex;
        justify-content: flex-end;
        align-items: center;
        padding-top: 10rpx;
    }
    .btns>view{
        font-size: 26rpx;
        padding: 12rpx 30rpx;
        border-radius: 50rpx;
        background-color: #f0f0f0;
    }
    
    
</style>

